package com.wolfking.jeesite.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 角色和菜单的关联关系
 * 
 * @author wolfking@赵伟伟
 * @mail zww199009@163.com
 * @创作日期 2017年5月13日 下午9:19:36
 * @copyright wolfking
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_role_office")
public class RoleOfficeRelation {

	@TableId(value = "id", type = IdType.AUTO)
	protected Integer id;

	@TableField("role_id")
	private Integer roleId;
	@TableField("office_id")
	private Integer officeId;

	public static List<RoleOfficeRelation> assemblyRelation(Role role) {
		Integer roleId = role.getId();
		String officeIds = role.getMenuIds();
		List<RoleOfficeRelation> list = Lists.newArrayList();
		if (StringUtils.isNotEmpty(role.getOfficeIds()))
			for (String officeId : officeIds.split(","))
				if (StringUtils.isNotEmpty(officeId))
					list.add(new RoleOfficeRelation(null,roleId, Integer.parseInt(officeId)));
		return list;
	}
}
